package JFreeChart_test;

import java.io.File;
import java.io.IOException;
import java.util.Random;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.statistics.HistogramDataset;
import org.jfree.data.statistics.HistogramType;
//import org.jfree.experimental.chart.swt.ChartComposite;


 public class HistogramExample {
       public static void main(String[] args) {
       double[] value = new double[100];
       Display display=new Display();
       Shell shell;
		shell = new Shell();
		shell.setMinimumSize(new Point(600, 400));
		shell.setSize(450, 300);
		shell.setText("SWT Application");
		shell.setLayout(new GridLayout());
//       Random generator = new Random();
//       for (int i=1; i < 100; i++) {
//       value[i] = generator.nextDouble();
//       System.out.println(value[i]);
//           int number = 10;
//       HistogramDataset dataset = new HistogramDataset(); // cr�e un histogramme
//       dataset.setType(HistogramType.RELATIVE_FREQUENCY);
//       dataset.addSeries("Histogram",value,number); // On ajoute le point avec les 2 coordonn�es valeur et nombre
//       String plotTitle = "Histogram"; 
//       String xaxis = "number";
//       String yaxis = "value"; 
//       PlotOrientation orientation = PlotOrientation.VERTICAL;  // On d�finit l�orientation de l�histogramme comme Vertical
//       boolean show = true; 
//       boolean toolTips = true;
//       boolean urls = true; 
//       JFreeChart chart = ChartFactory.createHistogram( plotTitle, xaxis, yaxis, 
//                dataset, orientation, show, toolTips, urls); // On cr�e l�histogramme avec les points ajout�s.
//       LegendItemCollection legend = new LegendItemCollection();
//       final ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart, 800, 600, 400, 300, 400, 300, true, true, true, true, true, true);
//       frame.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
//       frame.pack();
       shell.open();
       while (!shell.isDisposed()) {
           if (!display.readAndDispatch())
               display.sleep();
       }
       int width = 500;
       int height = 300; 
//        try {
//        	//ChartUtilities.saveChartAsPNG(new File("histogram.PNG"), chart, width, height); // permet de sauvegarder l�histogramme en tant que fichier PNG
//        } catch (IOException e) {}
      //}
   }
 }
